<?php

/**
 * CategoryModel
 *
 * @author Nguyen Hai Ha
 * @version
 */

require_once 'Zend/Db/Table/Abstract.php';

class CatcomModel extends Zend_Db_Table_Abstract {
	/**
	 * The default table name
	 */
	protected $_name = 'eway_catcom';
	protected $_dbAdapter;

	public function getAll(){
		$this->_dbAdapter = Zend_Registry::get(Constant::DB_ADAPTER);
		$sql = "SELECT * FROM ".$this->_name;
		$result = $this->_dbAdapter->fetchAll($sql);
		return $result;
	}

	public function getAllByComId($com_id){
		$this->_dbAdapter = Zend_Registry::get(Constant::DB_ADAPTER);
		$sql = "SELECT * FROM ".$this->_name." WHERE com_id=?";
		$result = $this->_dbAdapter->fetchAll($sql, $com_id);
		return $result;
	}

	public function insertCatcom($catcom=array()){
		$this->_dbAdapter = Zend_Registry::get(Constant::DB_ADAPTER);
		$this->_dbAdapter->insert($this->_name, $catcom);
		$id = $this->_dbAdapter->lastInsertId();
		return $id;
	}

	public function deleteByComId($com_id){
		$this->_dbAdapter = Zend_Registry::get(Constant::DB_ADAPTER);
		$where = "com_id=".$com_id;
		$this->_dbAdapter->delete($this->_name, $where);
	}

}
